export const setLocalStorageWithExpire = (key, value, expireMinutes) => {
    const now = new Date().getTime();
    const item = {
        value: value,
        expire: now + expireMinutes * 60 * 1000 // 计算过期时间的时间戳
    };
    try {
        localStorage.setItem(key, JSON.stringify(item));
    } catch (error) {
        console.error('设置localStorage数据出错:', error);
    }
};


export const getLocalStorageWithExpire = (key) => {
    try {
        const data = localStorage.getItem(key);
        if (data) {
            const item = JSON.parse(data);
            const now = new Date().getTime();
            if (now <= item.expire) {
                return item.value;
            } else {
                // 数据过期，移除该数据
                localStorage.removeItem(key);
                return null;
            }
        }
        return null;
    } catch (error) {
        console.error('获取localStorage数据出错:', error);
        return null;
    }
};


// 移除localStorage中的指定数据
export const removeItem = (key) => {
    try {
        localStorage.removeItem(key);
    } catch (error) {
        console.error('移除localStorage数据出错:', error);
    }
};